import java.util.HashMap;
import java.util.Map;

public class TestArray {


    public static void main(String[] args) {
        int[] array = {1,2,1};
        System.out.println(isArrayElementSingle(array));
    }

    /**
     * 判断数组中所有的数字是否只出现一次  复杂度O(n)
     */
    public static Boolean isArrayElementSingle(int[] array) {
        if (null == array) {
            throw new RuntimeException("传入的数组不能为空");
        }
        int length = array.length;
        if (length == 0) {
            throw new RuntimeException("传入的数组不能为空");
        }
        Map<Integer, Integer> map = new HashMap<>(16);
        for (int i : array) {
            Integer put = map.put(i, length);
            if (put != null) {
                return Boolean.FALSE;
            }
        }
        return Boolean.TRUE;
    }
}
